package com.kitty.spring.kittyUnifiedProcess.commons;

import com.kitty.spring.kittyUnifiedProcess.commons.constant.ResultConst;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 统一的返回类包含code、message
 * @Author SHEN
 * @Date 2020/10/10
 */

public class BaseResult extends HashMap<String, Object> {

    public BaseResult() {
        put("code", ResultConst.SUCCESS.getCode());
        put("message", ResultConst.SUCCESS.getMsg());
    }

    public BaseResult(String code, String message) {
        put("code",code);
        put("message",message);
    }

    public static BaseResult error(String code, String msg) {
        BaseResult r = new BaseResult(code,msg);
        return r;
    }

    public static BaseResult ok() {
        return new BaseResult();
    }

    public static BaseResult ok(String msg) {
        BaseResult r = new BaseResult(ResultConst.SUCCESS.getCode(), msg);
        return r;
    }

    public static BaseResult ok(Map<String, Object> map) {
        BaseResult r = new BaseResult();
        r.putAll(map);
        return r;
    }
    @Override
    public BaseResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public BaseResult put(Object value) {
        return put("data",value);
    }

}
